Bash Script Status Animation

#!/bin/bash

anim() {
    spinner="/|\\-"
    count=0
    while true; do
        printf "\r[${spinner:$count:1}] Loading..."
        count=$(( (count + 1) % 4 ))
        sleep 0.1
    done
}

save as loading_animation.sh and make it executable via chmod +x loading.sh

importing animation to other scripts

In this example I'm importing the animation script into an rsync shell script

#!/bin/bash

# Source (import) the external script
source ./loading_animation.sh

# Start the loading animation in the background
start_loading_animation &

# Store the PID of the loading animation
loading_animation_pid=$!

# Run your rsync command
rsync -av source/ destination/

# After rsync is done, stop the loading animation
kill $loading_animation_pid

# Clear the loading animation line
printf "\r%s\n" "                        "


Credits